import { _decorator, AudioClip, AudioSource, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

interface IAudioMap{
    [name: string]: AudioClip;
}

@ccclass('AuidoManager')
export class AuidoManager extends Component {
    private static instance: AuidoManager = null;
    //音乐列表
    @property([AudioClip])
    public audios: AudioClip[] = [];
    @property(AudioSource)
    public effect: AudioSource = null;
    private _dlct: IAudioMap = {};

    protected onLoad(): void {
        if (!AuidoManager.instance) {
            AuidoManager.instance = this;
        }
    }

    public static getInstance(): AuidoManager {
        return AuidoManager.instance;
    }

    start() {
        //记录名称
        for(let i = 0; i < this.audios.length; i++){
            this._dlct[this.audios[i].name] = this.audios[i];
        }
    }

    play(name: string){
        if(this._dlct[name]){
           this.effect.playOneShot(this._dlct[name]);
        }
    }
}


